/**
 * 
 */
package org.database.filter.internal;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.ws.rs.ext.Provider;

/**
 * @author tamnguyen
 * 
 */
@Provider
public class ConstraintViolationExceptionHandler extends
		AbstractExceptionHandler<ConstraintViolationException>
{

	@Override
	protected void appendMessage(Error error, ConstraintViolationException ex)
	{
		Set<ConstraintViolation<?>> violations = ex.getConstraintViolations();
		if (violations != null)
		{
			// TODO: just return a first validation error message. This should be extended to return
			// more information.
			for (ConstraintViolation<?> violation : violations)
			{
				error.setMessage(violation.getMessage());
				break;
			}
		}
	}

}
